package com.wondersgroup.core.util;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wanglei
 */
public class SysMsgSendUtil {
    private final SpringRestUtil util = new SpringRestUtil();
    private static String requestURI = "http://10.1.65.126:8408/NotificationManageProj/servlet/manageappkey";
    private final String requestVars = "?action={action}&res={res}&username={username}&message={message}&title={title}&uri={uri}&appkey={appkey}";
    private final String action = "sendWithOutHtmlByRes";
    public static String appkey = "dc0c9b98-2eb8-47d0-8e92-b51dbeb97c36";
    
    static {
        try {
            String uri = ConfigPropertiesUtil.getValue("sys.msg.send.uri");
            if(uri!=null){
                requestURI = uri;
            }
            String key = ConfigPropertiesUtil.getValue("sys.msg.send.appkey");
            if(key!=null){
                appkey = key;
            }
        } catch (Exception e) {
            Logger.getLogger(SysMsgSendUtil.class.getName()).log(Level.SEVERE, null, e);
        }
    }
    
    public void sendMessage(String appkey, String username, String title, String message, String uri){
        Map<String, String> variableMap = new HashMap<>();
        variableMap.put("action", action);
        variableMap.put("appkey", appkey==null?"":appkey);
        variableMap.put("res", appkey==null?"":appkey);
        variableMap.put("username", username==null?"":username);
        variableMap.put("title", title==null?"":title);
        variableMap.put("message", message==null?"":message);
        variableMap.put("uri", uri==null?"":uri);
        
        try {
            String s = util.processGet(requestURI+requestVars, null, variableMap, null).toString();
            System.out.println(s);
        } catch (Exception ex) {
            Logger.getLogger(SysMsgSendUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
